package com.homevip.user.dao;

import com.homevip.core.dao.BaseDaoWithQuery;
import com.homevip.core.page.Page;
import com.homevip.core.page.Pageable;
import com.homevip.user.entity.User_job;
import com.homevip.util.SqlHelper;
import com.homevip.util.StringUtil;
import org.springframework.stereotype.Repository;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.ArrayList;

/**
 * 工作Dao
 *
 */
@Repository
public class UserJobDao extends BaseDaoWithQuery<User_job, Integer> {
    @PersistenceContext
    private EntityManager em;

    public UserJobDao() {
        super(User_job.class);
    }

    @Override
    protected EntityManager getEntityManager() {
        // TODO Auto-generated method stub
        return em;
    }

    @Override
    public String toString() {
        // TODO Auto-generated method stub
        return super.toString();
    }

    @Override
    protected void finalize() throws Throwable {
        // TODO Auto-generated method stub
        super.finalize();
    }

    protected UserJobDao(Class<User_job> entityClass) {
        super(entityClass);
    }

    // 查询账号姓名和状态
    public Page<User_job> findByLikeWriter(String writer, Pageable pageable) {
        StringBuilder sb = new StringBuilder(128);
        ArrayList<Object> params = new ArrayList<Object>();
        sb.append("1=1");

        if (!StringUtil.isEmpty(writer)) {
            writer = SqlHelper.toJpqlParamLike(writer.trim());
            sb.append(" and writer like ?");
            params.add(writer.trim());
        }
        return queryBy(sb.toString(), params.toArray(), pageable);
    }

}
